package com.java.modebing.test.controller;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.java.modebing.test.annotation.RepeatSubmit;
import com.java.modebing.test.config.CommonConfig;
import com.java.modebing.test.enums.Scene;
import com.java.modebing.test.exception.CommonException;
import com.java.modebing.test.vo.GroupQueryReqVO;
import com.java.modebing.test.vo.TestVO;
import com.sun.org.apache.regexp.internal.RE;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RefreshScope
@AllArgsConstructor
public class CommonConfigController {

    private CommonConfig commonConfig;

    private static Integer count= 0;

    @GetMapping("/test/get")
    @RepeatSubmit(columns = {TestVO.NAME,TestVO.PHONE},sense = Scene.REQUEST)
    public String get(TestVO testVO) throws InterruptedException {
        Thread.sleep(5000);
        try {
            int i = 1/0;
        } catch (Exception e) {
            throw new CommonException(e.getMessage());
        }
        return commonConfig.getCommon();
    }

    @GetMapping("/test/get1")
    @RepeatSubmit(columns = {TestVO.NAME,TestVO.PHONE},sense = Scene.INVITATION)
    public String get1() throws InterruptedException {
        if (count%2 == 0){

        }else {
            Thread.sleep(5000);
        }
        count++;
        return commonConfig.getCommon();
    }


    @GetMapping("/test/get2")
    @RepeatSubmit(columns = {TestVO.NAME,TestVO.PHONE},sense = Scene.INVITATION)
    public String get1(GroupQueryReqVO groupQueryReqVO) throws InterruptedException {
        if (count%2 == 0){

        }else {
            Thread.sleep(5000);
        }
        count++;
        return commonConfig.getCommon();
    }

}

